package recompiled;

/**
 * TARGET PC: 0xA0000074
 */
public class A0000074 extends compiler.BasicBlock {

	private static final A0000074 INSTANCE = new A0000074();

	private A0000074(){}

	/**
	 * @see compiler.BasicBlock#getBasicBlock 
	 */
	public static compiler.BasicBlock getBasicBlock() {
		return INSTANCE;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void execute() throws mips.exceptions.MipsException {

		//0xa0000074 
		//0x8fc30028 
		//LW
		mips.CPU.GPR[3] = n64.MemoryManager.readWord(mips.CPU.GPR[30] + 40);
		
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;


		//0xa0000078 
		//0x24020001 
		//ADDIU
		u32_gpr_rs = mips.instructions.Instruction.zeroExtendW(mips.CPU.GPR[0]); 
		
		mips.CPU.GPR[2] = (int)((u32_gpr_rs + 1) & 4294967295L);
		
		mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;


		//0xa000007c 
		//0x14620005 
		//BNE
		if (mips.CPU.GPR[3] != mips.CPU.GPR[2]) {
			
			mips.CPU.PC = mips.CPU.nPC;
			mips.CPU.nPC = mips.CPU.PC + 20;
		} 
		else {
			
			mips.CPU.PC = mips.CPU.nPC;
			mips.CPU.nPC = mips.CPU.PC + 4;
		}


		if(!skipDelaySlot) {
			//0xa0000080 
			//0x00000020 
			//NOP
			mips.CPU.PC = mips.CPU.nPC;
		mips.CPU.nPC = mips.CPU.PC + 4;

		}
		
	}

	public static int instructionLength = 4;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int blockLength() {
		int returnLen = instructionLength;
		if(skipDelaySlot) {
			returnLen -= 1;
			skipDelaySlot = false;
		}
		return returnLen;
	}
}

